
<?php
defined( '_VALID_NVB' ) or die( 'Direct Access to this location is not allowed.' );
$sub = $_GET['dir'];
$path = $_SERVER['DOCUMENT_ROOT'].$CONFIG['dir_path']."/uploaded/";
alert($path);
$pathold=$_SERVER['DOCUMENT_ROOT']."/uploaded/";
$path = $path . "$sub";
$dh = opendir($path);
$i=1;?><style type="text/css">
<!--
a:link {
	color: #666666;
	text-decoration: none;
}
a:visited {
	color: #666666;
	text-decoration: none;
}
a:hover {
	color: #FF0000;
	text-decoration: none;
}
a:active {
	color: #FF0000;
	text-decoration: none;
}
.tdstyle {
	background:#FFFFFF;
}
.tdstyle:hover {
	background:#CCCCCC;
}
-->
</style>
<div style="width:550px; height:300px; overflow:scroll; border:solid 1px #CCCCCC;">
<div style="position:relative; clear:both; text-align:right; padding-right:20px; color:#333333; text-decoration:none; height:25px; background-color:#eeeeee; border-bottom:solid 1px"><a href="javascript:void(0)" onclick="closebrowsedir()" style="color:#333333; text-decoration:none">&#272;&#243;ng</a></div>
<table width="500px" border="0" >
  <tr>
  <?php 
  $i=0;
while (($file = readdir($dh)) !== false) {
	
	if($file != ".."){
		$i++;
		echo '<td style="width:100px; height:30px; border:solid #CCCCCC 1px; padding:4px" align="center" class="tdstyle"> <div style="width:100px; height:100px; overflow:hidden" class="tdstyle">';
		
		if($file != "." && $file != "..") {
			 if (substr($file, -4, -3) =="." || substr($file, -3, -2) =="." || substr($file, -5, -4) =="."){
				echo "<a style=\"cursor:pointer\" onclick=\"inserpathfile('".$sub."/".$file."'); closebrowsedir()\" title='".$file."'><img src='images/loudspeaker.png' align='center' border='0'><br>$file</a>";
			 }else{            
				echo '<a href="'."javascript:loadPage('?page=directory&dir=$sub/$file','showtree')".'"><img src="images/folder.png" align="center" border="0" title="'.$file.'"><br>'.$file.'</a>';
			}
			
		}else{
			if(backdir($path)!=$pathold && $file != ".."){
				echo  '<a href="javascript:'."loadPage('?page=directory&dir=".backdir($path)."','showtree')".'"><img border=0 src="images/undo.png"></a>';
			}
		}
		echo '<div></td>';
		if($i%4==0){
			echo "<tr>";
		}
	}
}
closedir($dh);


function backdir($path){
	global $pathold;
	$n=strlen($pathold);
	$pos= strrpos($path,'/');
	$a= substr($path,$n,$pos);
	$posx= strrpos($a,'/');
	return substr($a,0,$posx);
}
?> 

  </tr>
</table>

</div>
